package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.UserLJMService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @PackageName: com.itheima.controller
 * @ClassName: UserLJMController
 * @Author: LiuJunMeng
 * @Date: 2020/2/16 9:18
 * @Description: //TODO
 */
@RestController
@RequestMapping("/userLJM")
public class UserLJMController {
    @Reference
    private UserLJMService userLJMService;

    /**
     * 获取当前登录用户的菜单权限
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/getMenuList")
    public Result getUsername() throws Exception {
        try {
            User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            List<Map<String,Object>> menus = userLJMService.getMenuList(user.getUsername());
            return new Result(true, MessageConstant.GET_MENU_SUCCESS, menus);
        } catch (Exception e) {
            return new Result(false, MessageConstant.GET_USERNAME_FAIL);
        }
    }
}
